package com.mtons.mblog.modules.service.impl;

import com.alibaba.fastjson.TypeReference;
import com.mtons.mblog.base.utils.BeanUtils;
import com.mtons.mblog.modules.data.HistoryVO;
import com.mtons.mblog.modules.entity.History;
import com.mtons.mblog.modules.repository.HistoryRepository;
import com.mtons.mblog.modules.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * HistoryServiceImpl.
 * @author yuzhong
 * @date 2019/2/22 11:22
 */
@Service
@Transactional
public class HistoryServiceImpl implements HistoryService {

    @Autowired
    private HistoryRepository historyRepository;

    @Override
    public List<HistoryVO> findByToday() {
        List<History> histories = historyRepository.findByToday();
        List<HistoryVO> historyVOList = BeanUtils.copyProperties(histories, new TypeReference<List<HistoryVO>>(){});

        return historyVOList;
    }

    @Override
    public List<HistoryVO> findAll() {
        List<History> historyList = historyRepository.findAll();
        List<HistoryVO> historyVOS = BeanUtils.copyProperties(historyList, new TypeReference<List<HistoryVO>>(){});
        return historyVOS;
    }
}
